package sb.web;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import sb.ejb.ConfigBean;
import sb.entity.Partner;
import sb.util.MarkedListItem;

/**
 *
 * @author Pavel
 */
@ManagedBean
@RequestScoped
public class PartnersManagedBean {
	
	@PersistenceContext
	EntityManager em;
	
	@EJB
	ConfigBean configBean;
	
	public void fillDB() {
		configBean.createData();
	}
	
	// id
	private Long id;
	public void setId(Long id) {
		this.id = id;
	}
	public Long getId() {
		return id;
	}
	
	// partnersMarkedList
	private List<MarkedListItem<Partner>> partnersMarkedList;
	public void setPartnersMarkedList(List<MarkedListItem<Partner>> partnersMarkedList) {
		this.partnersMarkedList = partnersMarkedList;
	}
	public List<MarkedListItem<Partner>> getPartnersMarkedList() {
		return partnersMarkedList;
	}
	
	// choiceMode
	private String choiceMode = "0";
	public void setChoiceMode(String choiceMode) {
		this.choiceMode = choiceMode;
	}
	public String getChoiceMode() {
		return choiceMode;
	}
	
	public void markAsDeleted() {
		// this
	}
	
	public PartnersManagedBean() {
	}
	
	@PostConstruct
	public void init() {
		partnersMarkedList = new ArrayList<MarkedListItem<Partner>>();
		
        @SuppressWarnings("unchecked")
		List<Partner> list = (List<Partner>) em.createNamedQuery("partnerSelectAll").getResultList();
		for (Iterator<Partner> partnersIt = list.iterator(); partnersIt.hasNext();) {
			partnersMarkedList.add(new MarkedListItem<Partner>(partnersIt.next()));
		}
	}
}
